package com.free.freemarker.file;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.Map;

import freemarker.template.Template;

public class FileManager {

	public static File create(String path, String fileName, String suffix)
			throws IOException {
		File f = new File(path + "/" + fileName + suffix);
		f.getParentFile().mkdirs();
		if (!f.exists()) {
			f.createNewFile();
		}
		return f;
	}

	public static void complete(Template template, File file,
			Map<String, Object> root) throws Exception {
		Writer writer = new FileWriter(file);
		template.process(root, writer);
		writer.flush();
		writer.close();
	}
}
